import Vue from 'vue'
import Vuex from 'vuex'
import menu from './modules/menu/index.js'
import role from './modules/role/index.js'
import user from './modules/admin/index'
import spec from './modules/spec/index'
import specs from './modules/specs/index'
import spgl from './modules/spgl/index'
import ms from './modules/ms/index'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo:sessionStorage.getItem('userinfo')?JSON.parse(sessionStorage.getItem('userinfo')):null //个人登录资料
  },
  getters:{
    getUser(state){
      return state.userinfo
    }
  },
  mutations: {
    CHANGE_USER(state,payload){
      state.userinfo = payload
      //根据传入参数的不同可以考虑什么时候添加会话存储，什么时候移除会话存储
      if(payload){
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem('userinfo')
      }
    }
  },
  actions: {
    //封装一个修改登录个人信息的行动
    changeUserAction({commit},payload){
      commit('CHANGE_USER',payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    spec,
    specs,
    spgl,
    ms
  }
})
